<template>
  <view class="my-card-contanier" v-if="cart.length!=0">
    <!-- 收货地址组件 -->
    <my-address></my-address>
    <!-- 购物车标题 -->
    <view class="cart-title">
      <uni-icons type="shop" size="18" ></uni-icons>
      <text class="cart-item">购物车</text>
    </view>
    <!-- 购物车列表区域 -->
    <view class="care-list">
      <uni-swipe-action>
         <block v-for="(item,i) in cart" :key="i">
        <uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(item)">
          <my-goods :item="item" :showRadio="true" @radio-change="changeRadio" :showNumberBox="true" @num-change="changeNum"></my-goods>
        </uni-swipe-action-item>
         </block>
      </uni-swipe-action>
    </view>
    <!-- 结算组件 -->
    <my-settle></my-settle>
   
  </view>
  <view class="cart-null" v-else>
    <image class="cart-pic" src="/static/cart_empty@2x.png" mode=""></image>
    <text class="cart-text">空空如也~</text>
  </view>
</template>

<script>
  import badgeMix from "@/mixins/tabbar-badge.js"
  import { mapState,mapMutations } from  "vuex"
  export default {
    mixins:[badgeMix],
    data() {
      return {
         options: [{
              text: '删除', // 显示的文本内容
              style: {
                backgroundColor: '#C00000' // 按钮的背景颜色
              }
            }]
     }
    },
    computed:{
      ...mapState('my_card',['cart']),
    },
    methods:{
      ...mapMutations('my_card',['updataState','updataCount','deleteGoods']),
      // 改变商品勾选状态
      changeRadio(e){
        // console.log(e)
        this.updataState(e)
      },
      // 改变商品数量
      changeNum(e){
        // console.log(e)
        this.updataCount(e)
      },
      // 点击了滑动操作按钮
      swipeActionClickHandler(item) {
       this.deleteGoods(item.goods_id)
      }
    }
   
  }
</script>

<style lang="scss">
  .my-card-contanier {
    margin-bottom: 50px;
  }
.cart-title{
  height: 40px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 14px;
  border-bottom: 1px solid #C0C0C0;
  .cart-item {
    margin-left: 10px;
  }
}
.cart-null{
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 150px;
  .cart-pic {
    width: 90px;
    height: 90px;
  }
  .cart-text{
    color: gray;
    font-size: 12px;
    margin-top: 15px;
  }
}

</style>
